#Negative and Silencing Rates
#Alan Yan
#4-8-2020

#clear environment
rm(list = ls())

#load packages
library(pacman)
p_load(tidyverse,
       knitr,
       magick,
       webshot,
       kableExtra)

#load data
silencing <- read.csv("03-Silencing-Study/data/01-clean-data/clean_data.csv")
offensive <- read.csv("06-Pooled-Offensiveness/data/clean_data.csv")

#create a singler experimental condition variable
silencing$exp.cond <- ifelse(silencing$male == 1, "Male",
                                       ifelse(silencing$female == 1, "Female",
                                              ifelse(silencing$gen.neutral == 1, "Gender Neutral",
                                                     ifelse(silencing$no.name == 1, "No Name", NA))))
offensive$exp.cond <- ifelse(offensive$male == 1, "Male",
                                       ifelse(offensive$female == 1, "Female",
                                              ifelse(offensive$gen.neutral == 1, "Gender Neutral",
                                                     ifelse(offensive$no.name == 1, "No Name", NA))))

#Table S11 and S12
silencing %>%
  filter(gender != "Unknown") %>%
  group_by(exp.cond,
           gender,
           experiment1) %>%
  summarise(response_rate = sum(responded)/n()) %>%
  arrange(desc(experiment1),
          exp.cond,
          desc(gender)) %>%
  print(n = 16)

#subset to only those that responded
silencing.responded <- silencing[silencing$responded == 100,]
offensive.responded <- offensive[offensive$responded == 100,]

#Table 1
#offensive
mean(offensive.responded$offensive)
mean(offensive.responded$offensive[offensive.responded$experiment1 == 1])
mean(offensive.responded$offensive[offensive.responded$experiment1 == 0])

#silencing
mean(silencing.responded$pure.silencing)
mean(silencing.responded$pure.silencing[silencing.responded$experiment1 == 1])
mean(silencing.responded$pure.silencing[silencing.responded$experiment1 == 0])

#withdrawal
mean(silencing.responded$withdrawal)
mean(silencing.responded$withdrawal[silencing.responded$experiment1 == 1])
mean(silencing.responded$withdrawal[silencing.responded$experiment1 == 0])

#Table S4
prop.table(table(silencing$gender[silencing$experiment1 == 1]))
prop.table(table(silencing$gender[silencing$experiment1 == 0]))

#Table S5
prop.table(table(silencing$exp.cond[silencing$experiment1 == 1], silencing$gender[silencing$experiment1 == 1]), 1)

#Table S6
prop.table(table(silencing$exp.cond[silencing$experiment1 == 0], silencing$gender[silencing$experiment1 == 0]), 1)

#Table S10
silencing %>%
  group_by(experiment1,
           exp.cond) %>%
  summarise(response_rate = mean(responded))

#Table S14 and S15
silencing %>%
  group_by(experiment1,
           texter.id,
           exp.cond) %>%
  summarise(responded_count = sum(responded)/100) %>%
  group_by(experiment1,
           exp.cond) %>%
  summarise(responded_avg = mean(responded_count))

offensive %>%
  group_by(experiment1,
           texter.id,
           exp.cond) %>%
  summarise(offensive_count = sum(offensive)/100) %>%
  group_by(experiment1,
           exp.cond) %>%
  summarise(offensive_avg = mean(offensive_count))

silencing %>%
  group_by(experiment1,
           texter.id,
           exp.cond) %>%
  summarise(silencing_count = sum(pure.silencing)/100) %>%
  group_by(experiment1,
           exp.cond) %>%
  summarise(silencing_avg = mean(silencing_count))

silencing %>%
  group_by(experiment1,
           texter.id,
           exp.cond) %>%
  summarise(withdrawal_count = sum(withdrawal)/100) %>%
  group_by(experiment1,
           exp.cond) %>%
  summarise(withdrawal_avg = mean(withdrawal_count))

